import { createBrowserRouter, Link } from "react-router-dom";
import { ErrorBlock } from "antd-mobile";

//懒加载组件
let lazyhome = async () => {
  let { default: Home, loader } = await import("../pages/tabs/Home");
  return {
    element: <Home />,
    loader,
  };
};
//路由
const routes = createBrowserRouter([
  //重定向
  {
    path: "/",
    async lazy() {
      let { default: App } = await import("../App");
      return {
        element: <App />,
      };
    },
    //子路由
    children: [
      //索引路由
      {
        index: true,
        lazy: lazyhome,
      },
      //首页
      {
        path: "home",
        lazy: lazyhome,
      },
      //消息
      {
        path: "chat",
        async lazy() {
          let { default: Chat } = await import("../pages/tabs/Chat");
          return {
            element: <Chat />,
          };
        },
      },
      //我的
      {
        path: "me",
        async lazy() {
          let { default: Me } = await import("../pages/tabs/Me");
          return {
            element: <Me />,
          };
        },
      },
    ],
  },
  //注册
  {
    path: "/reg",
    async lazy() {
      let { default: Reg } = await import("../pages/auth/Reg.jsx");
      return {
        element: <Reg />,
      };
    },
  },
  //登录
  {
    path: "/login",
    async lazy() {
      let { default: Login } = await import("../pages/auth/Login.jsx");
      return {
        element: <Login />,
      };
    },
  },
  //城市搜索
  {
    path: "/city",
    async lazy() {
      let { default: City, loader } = await import("../pages/city");
      return {
        element: <City />,
        loader,
      };
    },
  },
  //景区首页
  {
    path: "/ticket",
    async lazy() {
      let { default: Ticket, loader } = await import("../pages/ticket");
      return {
        element: <Ticket />,
        loader,
      };
    },
  },
  //景区列表
  {
    path: "/list",
    async lazy() {
      let { default: List, loader } = await import("../pages/ticket/List.jsx");
      return {
        element: <List />,
        loader,
      };
    },
  },
  //景区详情
  {
    path: "/detail",
    async lazy() {
      let { default: Detail, loader } = await import(
        "../pages/ticket/Detail.jsx"
      );
      return {
        element: <Detail />,
        loader,
      };
    },
  },
  //404路由
  {
    path: "*",
    element: (
      <ErrorBlock
        fullPage
        description={<Link to="/">去首页</Link>}
      ></ErrorBlock>
    ),
  },
]);
export default routes;
